package models

import (
	"github.com/astaxie/beego/orm"
)

func init() {
	orm.Debug = true
}

type Video struct {
	Id            int
	VideoNumber   string
	Name          string
	ThumbSrc      string
	Cast          string
	VideoDuration string
	IssuingDate   string
	VideoSrc      string
	Views         int
	LikeNumber    int
	UnlikeNumber  int
	Score         float32
	Remarks       string
	Details       string
}

// 定义热门影片
type PopularWith struct {
	Video
}

// 定义最新影片
type NewVideo struct {
	Video
}

// 定义最高评分
type MaxScore struct {
	Video
}

// 定义最受关注影片
type Mostconcerned struct {
	Video
}

// 定义推荐影片
type Recommend struct {
	Video
}

// 获取热门影片
func GetPopularWith() ([]PopularWith, error) {
	var buffer []PopularWith
	o := orm.NewOrm()
	_, err := o.Raw("select * from video limit 8").QueryRows(&buffer)
	return buffer, err
}

// 获取最新影片
func GetNewVideo() ([]NewVideo, error) {
	var buffer []NewVideo
	o := orm.NewOrm()
	_, err := o.Raw("select * from video order by createtime DESC limit 6").QueryRows(&buffer)
	return buffer, err
}

// 获取最高评分影片
func GetMaxScore() ([]MaxScore, error) {
	var buffer []MaxScore
	o := orm.NewOrm()
	_, err := o.Raw("select * from video order by score DESC limit 6").QueryRows(&buffer)
	return buffer, err
}

// 获取最受关注影片
func GetMostConcerned() ([]Mostconcerned, error) {
	var buffer []Mostconcerned
	o := orm.NewOrm()
	_, err := o.Raw("select * from video limit 6").QueryRows(&buffer)
	return buffer, err
}

// 获取推荐影片
func GetRecommendVideo() ([]Recommend, error) {
	var buffer []Recommend
	o := orm.NewOrm()
	_, err := o.Raw("select * from video limit 5").QueryRows(&buffer)
	return buffer, err
}

// 获取影片详情
func GetVideDetails(video_number string) (Video, error) {
	o := orm.NewOrm()
	var user Video
	err := o.Raw(""+
		"select name,"+
		"video_number,"+
		"thumb_src,"+
		"video_duration,"+
		"like_number,"+
		"score,"+
		"unlike_number,"+
		"cast,"+
		"issuing_date,"+
		"views,"+
		"video_src,"+
		"details,"+
		"remarks"+
		" from video where video_number = ? limit 1 ", video_number).QueryRow(&user)
	return user, err
}

// 搜索影片
func GetSearchVideo(search_key string) ([]Video, error) {
	var buffer []Video
	o := orm.NewOrm()
	if search_key != "" {
		search_key = "%" + search_key + "%"
	}
	_, err := o.Raw("select * from video where name like ?", search_key).QueryRows(&buffer)
	return buffer, err
}

// 猜你喜欢
func GetRelatedVideos() {

}
